import { useEffect } from "react";
import { useReactive } from "ahooks";

function personInfoModel() {
	let state = useReactive({
		accountInfo: {},
		baseInfo: {},
		loginInfo: {},
		memberInfo: {},
		settings: {},
		identity: "guest", // 当前用户身份：guest 游客(未登录); localLogined  本地登录; remoteLogined 公共认证中心登录; temporaryLogined 公共认证中心临时登录
	});

	const getPersonInfoFromMain = async () => {
		const remotePersonInfo = await electron.getGlobal("personInfo");
		for (let key in remotePersonInfo) {
			state[key] = remotePersonInfo[key];
		}
	};

	useEffect(() => {
		getPersonInfoFromMain();
	}, []);

	const setPersonStateValue = (obj) => {
		for (let key in obj) {
			state[key] = obj[key];
		}
	};

	return {
		...state,
		setPersonStateValue,
	};
}

export default personInfoModel;
